<template>
  <div>
    <el-form ref="formMatter" :model="formMatter" :inline="true">
      <el-form-item label="顾客名称" prop="customerName">
          <el-select
          v-model="formMatter.customerName"
          placeholder="请输入顾客名称"
          filterable
          allow-create
          default-first-option
          clearable
          style="width: 7vw"
        >
          <el-option
            v-for="item in customerList"
            :key="item.id"
            :label="item.customerName"
            :value="item.customerName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="钢种" prop="steelGradeId">
        <el-select v-model="formMatter.steelGradeId" placeholder="请选择钢种" style="width: 6vw" filterable
        allow-create
        default-first-option clearable>
          <el-option v-for="item in steelGradeList" :key="item.id" :value="item.steelGradeName"
            :label="item.steelGradeName" />
        </el-select>
      </el-form-item>
      <el-form-item label="待处理事项" prop="itemId">
        <el-select v-model="formMatter.itemId" filterable
        allow-create
        default-first-option clearable size="mini" style="width: 7vw">
          <el-option v-for="item in pendList" :key="item" :value="item" :label="item" />
        </el-select>
      </el-form-item>
      <el-form-item label="钢类" prop="steelTypeId">
        <el-select v-model="formMatter.steelTypeId" filterable
        allow-create
        default-first-option clearable size="mini" style="width: 7vw">
          <el-option v-for="item in steelTypeList" :key="item.id" :value="item.steelTypeName" :label="item.steelTypeName" />
        </el-select>
      </el-form-item>
      <el-form-item label="标准" prop="standardName">
        <el-select v-model="formMatter.standardName" size="mini" filterable
        allow-create
        default-first-option clearable placeholder="请选择标准"
          style="width: 7vw">
          <el-option v-for="item in standardList" :key="item.id" :value="item.standardName"
            :label="item.standardName" />
        </el-select>
      </el-form-item>
      <el-form-item label="提交日期" prop="submitTime">
        <el-date-picker v-model="formMatter.submitTime" value-format="yyyy-MM-dd" type="date" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="编号" prop="code">
        <el-input v-model="formMatter.code" size="mini" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="getPendingProcessing()">查询</el-button>
        <el-button type="success" size="mini"
          @click="() => { $refs.formMatter.resetFields(); handleCurrentChange(1) }">重置</el-button>
      </el-form-item>
    </el-form>
    <el-card style="height: 100%">
      <div slot="header">待处理评审</div>
      <hmi-table :table-data="tableData" :table-head="true" :is-pagination-show="true"
        :table-height="'calc(100vh - 230px)'" :total="total" :current-page="formMatter.current"
        :page-size="formMatter.page" index-type="index" @handle-size-change="handleSizeChange"
        @handle-current-change="handleCurrentChange">

        <template slot="TableBody">
          <!-- <el-table-column label="序号" type="index" width="70" align="center"></el-table-column> -->
          <el-table-column label="编号" align="center" prop="code"></el-table-column>
          <el-table-column label="待处理事项" align="center" prop="itemName" width="110">
            <template slot-scope="scope">
              {{ scope.row.itemName }}
            </template>
          </el-table-column>
          <el-table-column label="顾客名称" align="center" prop="customerName" width="200"></el-table-column>
          <el-table-column label="顾客联系方式" align="center" width="160" prop="customerPhone"></el-table-column>
          <el-table-column label="钢类" align="center" prop="steelTypeName"></el-table-column>
          <el-table-column label="钢种" align="center" prop="steelGradeName"></el-table-column>
          <el-table-column label="标准" align="center" prop="standardName" show-overflow-tooltip></el-table-column>
          <el-table-column label="规格" align="center" prop="specification"></el-table-column>
          <el-table-column label="数量" align="center" prop="steelNumber">
            <template slot-scope="scope">
              {{ scope.row.steelNumber }}{{ scope.row.steelNumberUnit }}
            </template>
          </el-table-column>
          <el-table-column label="交货状态" align="center" prop="deliveryStatus"></el-table-column>
          <el-table-column label="加工用途" align="center" prop="processingPurpose"></el-table-column>
          <el-table-column label="提交时间" align="center" prop="submitTime" width="180">
            <template slot-scope="scope">
              <span>{{ formatterTime(scope.row.submitTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scoped">
              <el-button type="text" size="mini" @click="handle(scoped.row)">处理</el-button>
            </template>
          </el-table-column>
        </template>
      </hmi-table>
    </el-card>

  </div>

</template>

<script>
import HmiTable from "@/components/HmiTable.vue";
import { timeChange } from "@/lib/FormatTime";
import {
  GET_SALE_PENDREVIEW,
  GET_STEELGRADELIST,
  GET_STANDARDLIST,
  GET_STEELTYPELIST,
  GET_CUSTOMERNAMELIST
} from "@/lib/Api.js";
import { post, get } from "@/lib/Util.js";
export default {
  components: {
    HmiTable
  },
  data() {
    return {
      page: 20,
      total: 0,
      current: 1,
      formMatter: {
        code: "",
        current: 1,
        customerName: "",
        itemId: "",
        page: 5,
        standardName: "",
        steelGradeId: "",
        steelTypeId: "",
        submitTime: ""
      },
      pendList: [],
      steelGradeList: [],
      steelTypeList: [],
      standardList: [],
      tableData: [],
      customerList: []
    };
  },
  mounted() {
    this.getSteelGradeName();
    this.getStandardList();
    this.getPendingProcessing(); // 组件挂载后立即执行
    this.getsteelTypeNames(); // 获取钢类
    this.getCustomerNames(); // 获取顾客
  },
  methods: {
    /**
     * 格式化日期方法
     */
    formatterTime(time) {
      if (time !== "" && time !== undefined && time !== null) {
        return timeChange(time);
      } else {
        return "";
      }
    },
    getSteelGradeName() {
      post(GET_STEELGRADELIST, { steelGradeName: "" }).then(resp => {
        this.steelGradeList = resp.data;
      });
    },
    //获得标准
    getStandardList() {
      get(GET_STANDARDLIST).then(resp => {
        this.standardList = resp.data;
      });
    },
    getPendingProcessing() {
      post(GET_SALE_PENDREVIEW, this.formMatter).then(resp => {
        const { total, rows } = resp;
        this.total = total;
        this.tableData = rows;
      });
    },
    //当前页改变
    handleCurrentChange(current) {
      this.formMatter.current = current;
      this.getPendingProcessing();
    },
    //每页记录数改变
    handleSizeChange(page) {
      this.formMatter.page = page;
      this.handleCurrentChange(1);
    },
    handle(row) {
      let isShow = true;
      if (row.itemName == "保存待提交  ") {
        isShow = false;
      }
      this.$router.push({
        name: "pendOrder",
        params: {
          id: row.id,
          isShow: isShow
        }
      });
    },
    // 获取钢类
    getsteelTypeNames() {
      post(GET_STEELTYPELIST, { steelTypeName: "" }).then(resp => {
        this.steelTypeList = resp.data;
      });
    },
    // 获取顾客
    getCustomerNames() {
      post(GET_CUSTOMERNAMELIST, { customerName: "" }).then(resp => {
        this.customerList = resp.data;
      });
    }
  }
};
</script>

<style scoped>
</style>
